package com.demo.homework;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @ClassName 作业
 * @Description TODO
 * @Author tianqinglong
 * @Date 19:35 2022/7/12
 * @Version 1.0
 **/
public class 作业 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<?> b1 = Class.forName("com.demo.homework.Book");
        Book book = (Book) b1.newInstance();
        Constructor<?> constructor = b1.getDeclaredConstructor(int.class, String.class, float.class);
        System.out.println(constructor);

        Book book1 = (Book) constructor.newInstance(1, "水浒传", 100.0f);
        System.out.println(book1);
        Book b2 = (Book) b1.newInstance();
        Method declaredMethods = b1.getDeclaredMethod("sell",null);
        declaredMethods.invoke(b2,null);
     //   System.out.println(declaredMethods);

        Book b3 = (Book) b1.newInstance();
        Method declaredMethods1 = b1.getDeclaredMethod("sell",float.class,String.class);
        declaredMethods1.setAccessible(true);
        declaredMethods1.invoke(b3,100.0f,"张三");
        //System.out.println(declaredMethods1);
    }
}
class Book{
    private int bid;
    private String name;
    private float price;

    public Book() {
    }

    public Book(int bid, String name, float price) {
        this.bid = bid;
        this.name = name;
        this.price = price;
    }

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    public void sell(){
        System.out.println("书被卖了");
    }
    private void sell(float price,String person){
        System.out.println("书卖给了"+person+"，买了"+price+"元");
    }
}
